﻿using Plexi.Science;
using Plexi.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Plexi
{
	/// <summary>Stores data about a fake rock.</summary>
	public class RockInfo
	{
		public double Lat { get; set; }
		public double Lon { get; set; }
		public int RotationDegrees { get; set; }
		public int Xd { get; set; }
		public int Yd { get; set; }
		/// <summary>Not to be confused with "moved rocks", this merely indicates that in the current cell move operation, this rock has been already teleported to its new location.</summary>
		public bool Moved { get; set; }
		/// <summary>Indicates which one of the _rockPrefabs belongs to this rock.</summary>
		public int PrefabIndex { get; set; }
		public int IndexInCell { get; set; }
		public float Scale { get; set; }
		public bool IsMovable { get; set; }
		public RockData Data { get; set; }
		/// <summary>A number between 0 and 1, to be used as a multiplier to get an array index (see GetTexture()).</summary>
		public double TextureIndexSelector { get; set; }
		public RockInfo()
		{
			Moved = false;
			IsMovable = true;
			Data = new RockData();
		}

		/// <summary>Returns the mass of the rock, in tons.</summary>
		public float CalculateMass()
		{
			Data.Mass = (SurfaceRockSpawner.BaseRockVolume * Scale * Data.Type.SpecificWeight) / 1000f;
			return Data.Mass;
		}

		public UnityEngine.Texture GetTexture()
		{
			if (Data.Type.Textures == null || Data.Type.Textures.Length == 0) //something went wrong
			{
				Log.Add("ERROR: {0} has no textures!", Data.Type.Name);
				return Tools.TextureManager.FailTexture;
			}
			return Data.Type.Textures[(int)((Data.Type.Textures.Length - 1) * TextureIndexSelector)];
		}

		public int GetTextureIndex()
		{
			return (int)((Data.Type.Textures.Length - 1) * TextureIndexSelector);
		}
	}
}
